require('./model/index')
const User = require('./model/user')
const http = require('http')
const url = require('url')
const template = require('art-template')
const querystring = require('querystring')

const app = http.createServer();

app.on('request',(req,res)=>{
    const method = req.method;

    const {pathname,query} = url.parse(req.url, true);
    console.log(pathname)
    if(method == 'GET'){
        if(pathname == '/' || pathname == '/list'){
            let list = `<!DOCTYPE html>
                        <html lang="en">
                        <head>
                            <meta charset="UTF-8">
                            <title>用户列表</title>
                            <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css">
                        </head>
                        <body>
                            <div class="container">
                                <h6>
                                    <a href="/add" class="btn btn-primary">添加用户</a>
                                </h6>
                                <table class="table table-striped table-bordered">
                                    <tr>
                                        <td>用户名</td>
                                        <td>年龄</td>
                                        <td>爱好</td>
                                        <td>邮箱</td>
                                        <td>操作</td>
                                    </tr>
                                    <tr>
                                        <td>张三</td>
                                        <td>20</td>
                                        <td>
                                            <span>抽烟</span>
                                            <span>喝酒</span>
                                            <span>烫头</span>
                                        </td>
                                        <td>zhangsan@itcast.cn</td>
                                        <td>
                                            <a href="" class="btn btn-danger btn-xs">删除</a>
                                            <a href="" class="btn btn-success btn-xs">修改</a>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </body>
                        </html>
                               `;
            res.end(list)
        }
        else if (pathname == '/add'){
            let list = `<!DOCTYPE html>
                        <html lang="en">
                        <head>
                            <meta charset="UTF-8">
                            <title>用户列表</title>
                            <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css">
                        </head>
                        <body>
                            <div class="container">
                                <h3>添加用户</h3>
                                <form method="post" action="/add">
                                  <div class="form-group">
                                    <label>用户名</label>
                                    <input type="text" class="form-control" placeholder="请填写用户名">
                                  </div>
                                  <div class="form-group">
                                    <label>密码</label>
                                    <input type="password" class="form-control" placeholder="请输入密码">
                                  </div>
                                  <div class="form-group">
                                    <label>年龄</label>
                                    <input type="text" class="form-control" placeholder="请填写邮箱">
                                  </div>
                                  <div class="form-group">
                                    <label>邮箱</label>
                                    <input type="email" class="form-control" placeholder="请填写邮箱">
                                  </div>
                                  <div class="form-group">
                                    <label>请选择爱好</label>
                                    <div>
                                        <label class="checkbox-inline">
                                          <input type="checkbox" value="足球"> 足球
                                        </label>
                                        <label class="checkbox-inline">
                                          <input type="checkbox" value="篮球"> 篮球
                                        </label>
                                        <label class="checkbox-inline">
                                          <input type="checkbox" value="橄榄球"> 橄榄球
                                        </label>
                                        <label class="checkbox-inline">
                                          <input type="checkbox" value="敲代码"> 敲代码
                                        </label>
                                        <label class="checkbox-inline">
                                          <input type="checkbox" value="抽烟"> 抽烟
                                        </label>
                                        <label class="checkbox-inline">
                                          <input type="checkbox" value="喝酒"> 喝酒
                                        </label>
                                        <label class="checkbox-inline">
                                          <input type="checkbox" value="烫头"> 烫头
                                        </label>
                                    </div>
                                  </div>
                                  <button type="submit" class="btn btn-primary">添加用户</button>
                                </form>
                            </div>
                        </body>
                        </html>`;
            res.end(list)
        }
    }
    else if (method == 'POST'){

    }
})

app.listen(3000);
console.log('服务器创建成功')